package com.haoshuang.zhouzhoubang.ui.page.settled.background

import android.content.Context
import android.os.Bundle
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.ActivityBackgroundInputInfoBinding
import com.haoshuang.zhouzhoubang.model.bean.SettledInfoBean
import com.haoshuang.zhouzhoubang.ui.page.settled.settled.StoreSettledInputActivity
import com.mufeng.libs.base.BaseVMActivity
import com.mufeng.libs.state.observeState
import com.mufeng.libs.utils.startPage
import com.mufeng.libs.utils.view.click
import com.mufeng.libs.utils.view.clickWithTrigger
import com.mufeng.libs.utils.view.load
import com.mufeng.libs.utils.view.visibleOrGone


/**
 *  后台上传的详情
 */
class BackgroundInputInfoActivity :
    BaseVMActivity<BackgroundInputInfoViewModel, ActivityBackgroundInputInfoBinding>() {

    companion object {
        fun launch(context: Context) {
            context.startPage<BackgroundInputInfoActivity>()
        }
    }
    /**
     * 入驻信息实体
     */
    private var settledInfo: SettledInfoBean? = null
    override fun initView(savedInstanceState: Bundle?) {

        binding.titleBar.title = "门店入驻"
        binding.titleBar.leftImageView().click { finish() }

        binding.tvPreviewUpdate.clickWithTrigger {
            startPage<StoreSettledInputActivity>()
            finish()
        }

    }

    override fun initData() {
        vm.getStoreSettledInfo()
    }

    override fun startObserve() {
        vm.getStoreSettledInfoData.observeState(this) {
            onSuccess {
                settledInfo = it?.data
                setupData()
            }
        }
    }

    /**
     * 设置入驻信息
     */
    private fun setupData() {

        if (settledInfo != null) {

            // 姓名
            binding.etName.setText(settledInfo!!.real_name)
            // 手机号
            binding.etPhone.setText(settledInfo!!.mobile)
            // 身份证正面
            binding.rivUploadIDCardFront.load(
                settledInfo!!.card_front,
                placeholder = R.mipmap.icon_upload,
                error = R.mipmap.icon_upload
            )
            // 身份证反面
            binding.rivUploadIDCardBack.load(
                settledInfo!!.card_side,
                placeholder = R.mipmap.icon_upload,
                error = R.mipmap.icon_upload
            )

            // 门店名称
            binding.etStoreName.setText(settledInfo!!.team_name)
            binding.tvChooseEntity.text = if (settledInfo!!.is_entity == 1) "有实体店" else "没有实体店"
            binding.llTeamLogo.visibleOrGone(settledInfo!!.is_entity == 1)
            // 门店头像
            binding.rivUploadTeamHeadFront.load(settledInfo!!.team_logo)
            binding.rivUploadTeamHeadRight.load(settledInfo!!.team_right_logo)
            binding.rivUploadTeamHeadLeft.load(settledInfo!!.team_side_logo)
            // 门店地址
            binding.tvStoreAddress.text =
                "${settledInfo!!.province}${settledInfo!!.city}${settledInfo!!.area}${settledInfo!!.address}"
            // 门店人数
            binding.etStoreMemberNum.setText(settledInfo!!.team_num.toString())
            // 营业执照
            binding.rivBusinessLicense.load(
                settledInfo!!.team_company_pic,
                placeholder = R.mipmap.icon_upload,
                error = R.mipmap.icon_upload
            )
            // 门店简介
            binding.etStoreIntroduction.setText(settledInfo!!.synopsis)
            // 合作期限
            binding.tvCooperationTime.text = "${if (settledInfo!!.is_exp == "0") "无经验" else "有经验"} - ${settledInfo!!.service_year}年${if (settledInfo!!.is_pay_team_money == 0) "" else "/${settledInfo!!.join_money}元"}"
        }

    }

}